package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;

import com.google.common.collect.Lists;
import com.iwhalecloud.bss.kite.client.vo.scene.ModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProductModuleVO;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.CuccMemProdModuleVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.SceneNewOfferSeneVO;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberProductModuleHandler extends LocalAbstractProductModuleHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;
    /**
     * 执行当前组件
     *
     * @param context
     * @param sceneModule
     * @return 返回当前组件构建的对象，后面会将这个对象传给子组件，除非没有子组件，否则不应该返回null
     */
    @Override
    public List<CuccMemProdModuleVO> execute(AcceptContext context, SceneModule sceneModule) {
        List<ProductModuleVO> productModuleList = getViewSceneVo("member", context);
        productModuleList.removeIf(product -> !KiteStringUtils.equals(OfferCache.get(product.getOfferId()).getCateId(), "2004010"));

        CuccMemProdModuleVO memProdModuleVO = new CuccMemProdModuleVO();
        memProdModuleVO.setProduct(productModuleList);
        ((SceneNewOfferSeneVO) context.getSceneVo()).getSceneProductModuleVO().setMemberProduct(memProdModuleVO);
        return Lists.newArrayList(memProdModuleVO);
    }

    @Override
    public List<? extends ModuleVO> previewSceneVo(AcceptContext context, SceneModule sceneModule) {
        List<CuccMemProdModuleVO> productModuleList = this.execute(context, sceneModule);
        productModuleList.forEach(memProdModule -> {
            memProdModule.setIsEdit(KeyConsts.IFTRUE_F);
        });
        return productModuleList;
    }
}
